package common.servlet;

import java.io.*;
import java.util.Properties;

import javax.servlet.*;
import javax.servlet.http.HttpServlet;

import common.Configuration;
import common.dal.Creator;
import common.logger.*;
import common.logger.Logger.LogLevel;

/**
 * A servlet class that initializes all server data
 * 
 * @author Gal Lalouche
 */
public class Initiator extends HttpServlet {
	private final Logger	logger	= CompositeLogger.getInstance();
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		Properties props = new Properties();
		String path = getServletContext().getRealPath("//");
		Configuration.getInstance().setRealPath(path);
		// System.setProperty("pwd", path);
		try {
			props.load(new FileInputStream(path + "/dbs.properties"));
			Configuration.getInstance().setProps(props);
			logger.log(LogLevel.INFO, "props file succesfuly loaded");
			Creator.createAll();
		} catch (IOException e) {
			throw new ServletException("error loading props file");
		}
	}
}
